package com.liu.head.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import com.liu.common.pojo.InfoEnum;
import com.liu.common.util.ConstatFinalUtil;
import com.liu.users.pojo.AUsers;

/**
 * 拦截器
 * @author lby
 *
 */
@Component
public class AuthInterceptor implements HandlerInterceptor 
{
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
	{
		ConstatFinalUtil.LOGGER.info("==过你器执行==");
		HttpSession session = request.getSession();
		AUsers usersSess = (AUsers)session.getAttribute("usersSess");
		if(usersSess !=null)
		{
			return true ;
		}
		/*返回信息，否则白页面*/
		session.setAttribute("info", InfoEnum.INFO_LOGIN_ILLEGAL.getInfo());
		response.sendRedirect(request.getContextPath() + "/login");
		return false;
	}
}
